import * as ui from "../common/ui/pop_mgr";
import { TimerMgr } from "../common/timer/timer_mgr";
import { RandomUtil } from "../common/random/RandomUtil";
import { AudioPlayer } from "../common/audio/AudioPlayer";
import { EventDispatch, Event_Name } from "../common/event/EventDispatch";
import { Tween } from "../common/tween/Tween";
import Enemy from "./Enemy";
import Player from "./Player";

const { ccclass, property } = cc._decorator;

@ccclass
export default class New extends cc.Component {
    @property(cc.Sprite)
    self: cc.Sprite = null;

    @property(Array(cc.Sprite))
    enemyArr: Array<cc.Sprite> = [];

    @property(cc.Camera)
    camera: cc.Camera = null;

    onLoad() {
        cc.director.getPhysicsManager().enabled = true
        // this.self.getComponent(cc.RigidBody).onEndContact = this.onEndContact(x,y,z)
    }

    protected start(): void {
        for (let key in this.enemyArr) {
            let enemy = this.enemyArr[key]
            let aa = enemy.addComponent(Enemy)
            aa.setTarget(this.self.getComponent(Player))
        }

    }
    onEndContact(x, u, z) {

    }


    update(dt: number) {
        for (let key in this.enemyArr) {
            let enemy = this.enemyArr[key]
            enemy.getComponent(Enemy).update(dt)
        }
        this.camera.node.setPosition(this.self.node.getPosition())

    }
}

// 欢迎关注【白玉无冰】公众号